// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import 'element-ui/lib/theme-chalk/display.css';
import App from './App'
import router from './router'
import store from './store'
import axios from 'axios'
import VueAxios from 'vue-axios'
import VueRouter from  'vue-router'
import Vuex from 'vuex'
import apiUrl from './components/Global.vue'
import 'babel-polyfill'
Vue.prototype.apiUrl1 = apiUrl.apiUrl1;
Vue.prototype.apiUrl2 = apiUrl.apiUrl2;
Vue.prototype.apiUrl3 = apiUrl.apiUrl3;
Vue.prototype.apiUrl4 = apiUrl.apiUrl4;
Vue.prototype.apiUrl5 = apiUrl.apiUrl5;
Vue.prototype.apiUrl6 = apiUrl.apiUrl6;
Vue.use(Vuex)
Vue.use(VueRouter)
Vue.use(VueAxios, axios)
Vue.use(ElementUI);
Vue.use(VueRouter)
Vue.config.productionTip = false

// 在请求头中加token
axios.interceptors.request.use(
  config => {
  // 判断是否存在token，如果存在的话，则每个http header都加上token
    let token = sessionStorage.getItem('Authorization')
    if (!config.headers.hasOwnProperty('Authorization') && token) {
      config.headers.Authorization = token;
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  });

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  // 启用 ElementUI
   render: h => h(App)
})
